function [protocol, rate, records, pts, frec, lrec, time, TM, ZT, TL, VL] = analysis_setup2(DFILE, sf)

global CONTROL CURRENT

time = [];

% abstract general information
protocol=deblank(lower(CONTROL(sf).protocol));
rate = DFILE.rate.*DFILE.nr_channel/1000;
[records,pts]=size(CURRENT);

[RL, err] = record_parse(CONTROL(sf).reclist);
frec=min(RL);
lrec=max(RL);

%QueMessage('Analysis setup:  time base');
% compute the time base for plotting (time is [rec, npts] array for EACH record)
time=make_time(DFILE);
tmax=max(max(time));
k = find(DFILE.rate < 1);
DFILE.rate(k) = 50;
RATES = (DFILE.rate .* DFILE.nr_channel)/ 1000; % array of sampling rates, convert to msec

% always compute the time of each stimulus, in seconds from the start of the data
%QueMessage('Analysis setup:  time base 2');
if(DFILE.mode >= 5)
    wz=DFILE.ztime;
    w=find(diff(wz) < -12*60*60); % correct for possibility that someone actually records the data across midnight rollover.... (yes, it happened. 5/16/01 with Huijie's data.)
    if(~isempty(w))
        wz(w+1:end)=wz(w+1:end)+24*60*60;
    end;
    zt = (wz-wz(1))/(60);
    cond_baseline = 5; % 5 min baseline
else
    zt = (DFILE.ztime-DFILE.ztime(1))/(60*1000);
    cond_baseline = 3;
end;
TM=zt;

%QueMessage('Analysis setup:  time base 3');
if(DFILE.mode >= 5)
    wz=DFILE.ztime;
    w=find(diff(wz) < -12*60*60); % correct for possibility that someone actually records the data across midnight rollover.... (yes, it happened. 5/16/01 with Huijie's data.)
    if(~isempty(w))
        wz(w+1:end)=wz(w+1:end)+24*60*60;
    end;
    ZT = (wz-wz(1))/(60);
    cond_baseline = 5; % 5 min baseline
elseif length(DFILE.ztime) == length(RL)
    ZT = (DFILE.ztime-DFILE.ztime(1))/(60*1000);
    cond_baseline = 3;
else
    ZT = ones(length(RL), 1)*DFILE.cycle;
    cond_baseline = 5;
end;

% access ZT with the record number (1..n) to get the corresponding ztime
% have to get the records first

% Now, get the times when the valves switched (if any...)
% and generate periods with valve 1, 2, 3 or 4.
%QueMessage('Analysis setup:  Valves...');
p=datac('getnote'); % read the current notefile information.
t_sw_valve=[];
n_valve=[];
TL=[];
VL=[];
if(~isempty(p) & length([p.proto]) > 0) % there should be some, but if not, don;'t do much
    % first set of arrays are immediate representations.
    sw_valve=[1 [p(find(diff([p.valve])~=0)+1).frec]];	% valve switch list (records)
    if(length(sw_valve) > 1)
        n_valve=[1 p(find(diff([p.valve])~=0)+1).valve]; % which valve...
        t_sw_valve=ZT(sw_valve); % don't forget offset from start of data..
        % now make long time arrays to match the other arrays.
        for i = frec:lrec
            TL(i)=ZT(i);
            for j=1:length(sw_valve)
                if(i >= sw_valve(j))
                    VL(i)=n_valve(j);
                end;
            end;
        end;
    end;
end;
